@extends('admin.layout.layout')
@section('title','新闻列表')
@section('con')
<div id="page-wrapper" style="min-height: 349px;">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">新闻列表</h1>
                </div>
                <!-- /.col-lg-12 -->
            </div> 
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            新闻列表
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                <div class="row">
                                <form action="{{url('/admin/news/index')}}" method="get" >
	                                <div class="col-sm-6">
                                        <div id="dataTables-example_filter" class="dataTables_filter">
                                            <label><input name="keywords" value="{{ $list['keywords'] or '' }}" type="search" class="form-control input-sm" placeholder="输入作者或标题" aria-controls="dataTables-example" /></label>
                                            <button class="btn btn-primary" >查询</button>
                                        </div>          
                                        
                                    </div>
                                    <div class="col-sm-6">
	                                </div>
                                   
                                </form>
                                <div class="row">
                                	<div class="col-sm-12">
                                		<table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info">
                                    		<thead>
                                    			<tr>
		                                    		<th>新闻Id号</th>
                                                    <th>作者</th>
                                                    <th>小编</th>
                                                    <th>新闻标题<span style="color:#9999A6;font-size:12px;">(点击标题查看内容)</span></th>
                                                    <th>发表时间</th>
                                                    <th>评论数</th>
                                                    <th>阅览量</th>
		                                    		<th>操作</th>
                                    			</tr>
                                    		</thead>
                                    	<tbody>
                                    	@foreach($news as $k=>$v)
		                                    <tr class="gradeA odd" role="row">
                                                <td class="sorting_1">{{$v->nid}}</td>
                                                <td class="sorting_2">{{$v->nname}}</td>
		                                        <td class="sorting_2">{{$v->username}}</td>
                                                <td class="center" style="width:300px;"><div style="overflow:hidden; text-overflow:ellipsis; white-space:nowrap;width:300px;"><a href="#"  class="showNew" data-toggle="modal" data-target="#myModal_{{$v->nid}}" title="{{$v->sntitle}}">{{$v->ntitle}}</a></div> </td>
                                                <td class="sorting_3">{{$v->nctime}}</td>
                                                <td class="sorting_4">{{$v->num}}</td>
                                                <td class="sorting_5">{{$v->rnum}}</td>
		                                        <td class="center">
		                                        	<button  class="btn btn-danger btn-sm delete-btn" type="button" title="删除帖子">
                                                      删除
                                                    </button>
                                                    <a href="{{url('/admin/news/edit',['nid'=>$v->nid])}}" class="btn btn-sm  btn-success">修改</a>
		                                        </td>
		                                    </tr>
                                                <!-- Modal -->
                                                <div class="modal fade" id="myModal_{{$v->nid}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                                  <div class="modal-dialog">
                                                    <div class="modal-content">
                                                      <div class="modal-header" >
                                                        <button onclick="$(this).parents('div').find('.showcomment').empty();" type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
                                                        <h4 class="modal-title"  id="myModalLabel">{{$v->ntitle}}</h4>
                                                      </div>
                                                      <div class="modal-body">
                                                        {!! $v->ncon !!}
                                                      </div>
                                                      <div class="modal-footer showcomment">

                                                      </div>
                                                      <div class="modal-footer">
                                                        <button onclick="$(this).parents('div').find('.showcomment').empty();" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                                      </div>
                                                    </div>
                                                  </div>
                                                </div>
		                                @endforeach
                                    	</tbody>
                                </table>
                                </div>
                                </div>
                                <div class="row" style="margin:0px auto">
									{!! $news->appends($list)->render() !!}
                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
@endsection
@section('js')
<script type="text/javascript">     
    $.ajaxSetup({
        headers:{
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    //绑定单击事件
    $('.showNew').click(function(){
        //获取nid
        var nid = $(this).parents('tr').find('.sorting_1').html();
        //发送ajax
        $.get('/admin/news/select',{nid:nid},function(data){
            if (data != null) {
                eval('var obj ='+ data);
                var div = $('.showcomment');
                var str = '';
                for (var i = 0; i <  obj.length; i++) {
                    str += '<div class=""><p>'+obj[i].cncont+'</p><h5>评论者:'+obj[i].username+'</h5>&nbsp;&nbsp;&nbsp;'+obj[i].cntime+'&nbsp;'+(i+1)+'楼</div><hr>' ;
                      div.html(str);      
                };
            };
        });
    });


     //绑定单击事件
    $('.delete-btn').click(function(){
        if (confirm('确定要删除吗?')) {
             var id = $(this).parents('tr').find('.sorting_1').html();
             var btn = $(this);

             //发送ajax请求
             $.get('/admin/news/delete',{nid:id},function(data){
              if (data == 1) {
                //删除成功
                    alert('删除成功');
                    btn.parents('tr').remove();
                }else{
                //删除失败
                    alert('删除失败');
                }
            })
        }
        })


</script>
@endsection